#ifndef LEVEL_H
#define LEVEL_H

#include "map.h"
#include "player.h"
#include "monster.h"
#include "rock.h"
#include "block.h"
#include "fruit.h"

class Level
{
public:
    Level();
    Level(Map *map, Player *player);
    ~Level();

    Map *getMap() const;
    Player *getPlayer() const;
    QList<Monster*> getMonsters() const;
    QList<Rock*> getRocks() const;

    void setMap(Map *map);
    void setPlayer(Player *player);
    void addMonster(Monster *monster);
    Monster *getMonsterAt(int pos);
    void addRock(Rock *rock);
    Rock *getRockAt(int pos);

    void init();
    bool isWin();
    bool playerCollidesWithMap(Player *player);
    bool playerCollidesWithMonster(Player *player);
    bool playerCollidesWithRock(Player *player);
    bool movingUnitCollidesWithMap(MovingUnit *movingUnit);
    void movingUnitStoppedByMovingUnits(MovingUnit *movingUnit, QList<MovingUnit*> &movingUnits);
    bool monsterCollidesWithPlayer(Monster *monter);
    bool monsterCollidesWithRock(Monster *monster);
    void monsterCollides(Monster *monster);
    bool rockPushingCollidesWithMovingUnits(Rock *rock);
    bool rockFallingCollidesWithMovingUnits(Rock *rock);
    bool rockCollides(Rock *rock);
    void advance();

    void serializeDebug(QDebug &dbg);
    void serializeIn(QDataStream &in);
    void serializeOut(QDataStream &out);

private:
    Map *m_map;
    Player *m_player;
    QList<Monster*> m_monsters;
    QList<Rock*> m_rocks;

    int m_countMonsters;
    int m_countFruits;
    bool m_win;

};


QDataStream & operator << (QDataStream &out, Level* level);
QDataStream & operator >> (QDataStream &in,  Level* level);
QDebug operator<<(QDebug dbg, Level* level);

#endif // LEVEL_H
